/**
 * 获取请求GET变量
 */
function getQueryParam(item){
	var svalue = location.search.match(new RegExp('[\?\&]' + item + '=([^\&]*)(\&?)','i'));
	return svalue ? decodeURIComponent(svalue[1]) : '';
} 
	
var editorTools = 'Pastetext,|,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,Removeformat,|,Align,List,Outdent,Indent,|,Link,Unlink,Img,Flash,Media,Emot,Table,|,Source,Fullscreen,About';

/**
 * 重置编辑器的高度
 */
function editorHigher(px) {
	var xheHeight = $('.xheIframeArea').height()+px;
	if(xheHeight > 1200 || xheHeight < 100) return false;
	$('.xheIframeArea').css('height', xheHeight+'px')
	$('.xheLayout').css('height', 'auto');
}

/**
 * 构建JSON格式数据对象
 *
 * usage：
 * var jb = new JsonBuilder();
 * jb.add('field A', 'str'); // 添加json key/value 项
 * jb.add('数据项 B', '内容'); // 添加json key/value 项
 * alert(jb.getJson()); // 获取所构建的json数据
 */
function JsonBuilder () {
	var data = new Object();
	
	/**
	 * 添加key/value数据项
	 * 
	 * @param key json数据项下标
	 * @param val json数据项的值
	 */
	this.add = function (key, val) {
		data[key] = val;
	}
	
	/**
	 * 获取json数据
	 */
	this.getJson = function () {
		var s = '';
		for(var k in data) {
			if(s.length > 0) {
				s += ',';
			}

			s += "'" + k.replace(/'/g, "\\\'") + "'" + ': \'' + data[k].replace(/'/g, "\\\'") + '\'';
		}

		return '{'+s+'}';
	}
}

/**
 * 在页面中创建弹出div窗口
 * 窗口样式在global样式中
 *
 * @param width 窗口宽 （默认560）
 * @param height 窗口高 （默认410）
 */
function creatPopBox(title, width, height, content) {
	if(typeof(title) == 'undefined') title = '';
	if(typeof(height) == 'undefined') height = 410;
	if(typeof(width) == 'undefined') width = 560;
	if(typeof(content) == 'undefined') content = '<div class="floor-loading"></div>';
	
	var popBoxPos = PopBoxPos(width, height);
	$('#pop-box').css('left', popBoxPos.left+'px');
	$('#pop-box').css('top', popBoxPos.top+'px');	

	$('#pop-box, #pop-box-out').remove();
	
	var style = ' left:' + popBoxPos.left +'px;'
	          + ' top:' + popBoxPos.top + 'px;'
			  + ' height:' + ((parseInt(height) == 0) ? 'auto;' : height + 'px;')
			  + ' width:' + width + 'px;';
			  
	var html = '<div id="pop-box-out"></div>'
			 + '<div id="pop-box" style="'+style+'">'
			 + '  <a class="close"></a>'
			 + '  <div class="pop-box-in">'
			 + '    <div class="in-wrap">'
			 +        (title == '' ? '' : '<h1 class="pop-title">'+title+'</h1>')
			 + '      <div id="pop-main">'+content+'</div>'
			 + '    </div>'
			 + '  </div>'
			 + '</div>'
	$('body').append(html);
	
	//dragable('pop-box', '.pop-title');
	
	$('#pop-box .close').click(function(){$('#pop-box, #pop-box-out').remove();});
		
	$(window).resize(function(){
		if($('#pop-box').height() == null) return;
		var popBoxPos = PopBoxPos(width, height);
		$('#pop-box').css('left', popBoxPos.left+'px');
		$('#pop-box').css('top', popBoxPos.top+'px');
	});
}

/**
 * 关掉浮动窗口
 */
function removePopBox() {
	$('#pop-box').remove();
	$('#pop-box-out').remove();
}
/**
 * 获取浮动窗口层的位置
 */
function PopBoxPos(width, height) {
	var pageWidth = window.innerWidth;
	var pageHeight = window.innerHeight;
	if (typeof pageWidth != "number"){
		if (document.compatMode == "CSS1Compat"){
			pageWidth = document.documentElement.clientWidth;
			pageHeight = document.documentElement.clientHeight;
		} else{
			pageWidth = document.body.clientWidth;
			pageHeight = document.body.clientHeight;
		}
	}
	
	var top = ((pageHeight - height)/2)+$(window).scrollTop();
	var left = (pageWidth - width)/2+$(window).scrollLeft();
	
	return {'left':left, 'top':top};
}
/**
 * 使层可拖动
 * 
 * @param string o 可拖动层的id
 * @param string moveTag 光标显示为可移动的元素， 可用id，类，标签，如#xx、.xx或xx 
 */
function dragable(o, moveTag) {  
    if (typeof o == "string") o = document.getElementById(o);  
    o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;  
    o.orig_y = parseInt(o.style.top) - document.body.scrollTop;  
    o.orig_index = o.style.zIndex;
	
	o.onmouseover = function (a) {
		$(moveTag).css('cursor', 'move');
	}
	
	o.onmouseout = function (a) {
 		$(moveTag).css('cursor', 'normal');
	}
	
    o.onmousedown = function(a) {  
        this.style.zIndex = 10000;
        var d  = document;
        if(!a) a = window.event;
        var x = a.clientX + d.body.scrollLeft - o.offsetLeft;
        var y = a.clientY + d.body.scrollTop - o.offsetTop;

        d.ondragstart = "return false;"
        d.onselectstart = "return false;"
        d.onselect = "document.selection.empty();"

        if(o.setCapture) {
            o.setCapture();
		} else if(window.captureEvents) {
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		}

        d.onmousemove = function(a) {
            if(!a) a = window.event;
            $('#'+o.id).css('left', a.clientX+document.body.scrollLeft-x + 'px');
            $('#'+o.id).css('top', a.clientY+document.body.scrollTop-y + 'px');
			
            o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
            o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
        }
		
        d.onmouseup = function() {
            if(o.releaseCapture) {
                o.releaseCapture();
			} else if(window.captureEvents) {
                window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			}

            d.onmousemove = null;
            d.onmouseup = null;
            d.ondragstart = null;
            d.onselectstart = null;
            d.onselect = null;
            o.style.cursor = "normal";
            o.style.zIndex = o.orig_index;
        }
    }
	
	var orig_scroll = window.onscroll ? window.onscroll:function (){};
	window.onscroll = function () {
		orig_scroll();
		o.style.left = o.orig_x + document.body.scrollLeft;
		o.style.top = o.orig_y + document.body.scrollTop;
	}
}

function divLoadPage(div, url, json) {
	$.ajaxf.ready(function(){
		$(div).html('<div class="floor-loading"></div>');
		
		$.ajaxf.postText(url, json, function(r) {
			$(div).html(r);
		});

	});
}
$(document).ready(function(){
	$(".note, .msg-list tr, .list tr, .list li").hover(
		function () {$(this).addClass("note-hover");},
		function () {$(this).removeClass("note-hover");}
	);
});



/**
 * 设置cookie
 * 
 * @param string name
 * @param string value
 * @param Day expireDays 多少天后过期
 */
function setCookie(name, value, expireDays) {
	var exp = '';

	if(expireDays != null) {
	    var exDate = new Date();
	    exDate.setDate(exDate.getDate() + expireDays);
		exp = ";expires=" + exDate.toGMTString();
	}

	document.cookie = name + "=" + escape(value) + exp + "; path=/";
}

/**
 * 读取cookie
 *
 * @param string name
 */
function getCookie(name) {
    if (document.cookie.length > 0) {
        start = document.cookie.indexOf(name + "=");
	    if (start != -1) {
		    start = start + name.length + 1;
            end = document.cookie.indexOf(";", start);
            if (end == -1) end = document.cookie.length;

            return unescape(document.cookie.substring(start, end));
        }
    }

    return "";
}

/**
 * 删除cookie
 *
 * @param string name
 */
function delCookie(name) {
	net.mjie.Cookies.setCookie(name, "", -1);
}